package jwlee.testjms;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;

public class ActiveMQTest {

	public static void main(String[] args) throws Exception {
		ConnectionFactory factory = new ActiveMQConnectionFactory("vm://10.13.0.22");

		Connection connection = factory.createConnection();
		connection.start();

		Queue queue = new ActiveMQQueue("mzjQueue");

		final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		Message sendMessage = session.createTextMessage("Hello JMS!");

		MessageProducer producer = session.createProducer(queue);
		producer.send(sendMessage);
		System.out.println("Sender: " + ((TextMessage) sendMessage).getText());

		MessageConsumer comsumer = session.createConsumer(queue);
		Message receiveMessage = comsumer.receive();
		System.out.println("Receiver: " + ((TextMessage) receiveMessage).getText());

		connection.stop();
	}
}
